package com.ruoyi.web.controller.system;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysMorePicture;
import com.ruoyi.system.service.ISysMorePictureService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 轮播图Controller
 *
 * @author ruoyi
 * @date 2020-08-13
 */
@Controller
@RequestMapping("/system/picture")
public class SysMorePictureController extends BaseController {
    private String prefix = "system/picture";

    /**
     * 陈氏春秋testGit
     */

    String a = "";

    @Autowired
    private ISysMorePictureService sysMorePictureService;

    @RequiresPermissions("system:picture:view")
    @GetMapping()
    public String picture() {
        return prefix + "/picture";
    }

        /**
         * 查询轮播图列表
         */
        @RequiresPermissions("system:picture:list")
        @PostMapping("/list")
        @ResponseBody
        public TableDataInfo list(SysMorePicture sysMorePicture) {
            startPage();
            List<SysMorePicture> list = sysMorePictureService.selectSysMorePictureList(sysMorePicture);
            return getDataTable(list);
        }
    
    /**
     * 导出轮播图列表
     */
    @RequiresPermissions("system:picture:export")
    @Log(title = "轮播图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysMorePicture sysMorePicture) {
        List<SysMorePicture> list = sysMorePictureService.selectSysMorePictureList(sysMorePicture);
        ExcelUtil<SysMorePicture> util = new ExcelUtil<SysMorePicture>(SysMorePicture. class);
        return util.exportExcel(list, "picture");
    }

            /**
         * 新增轮播图
         */
        @GetMapping("/add")
        public String add() {
            return prefix + "/add";
        }
    
    /**
     * 新增保存轮播图
     */
    @RequiresPermissions("system:picture:add")
    @Log(title = "轮播图", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysMorePicture sysMorePicture) {
        return toAjax(sysMorePictureService.insertSysMorePicture(sysMorePicture));
    }

    /**
     * 修改轮播图
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        SysMorePicture sysMorePicture =sysMorePictureService.selectSysMorePictureById(id);
        mmap.put("sysMorePicture", sysMorePicture);
        return prefix + "/edit";
    }

    /**
     * 修改保存轮播图
     */
    @RequiresPermissions("system:picture:edit")
    @Log(title = "轮播图", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysMorePicture sysMorePicture) {
        /*陈氏春秋*/
        String a = "";
        return toAjax(sysMorePictureService.updateSysMorePicture(sysMorePicture));
    }

            /**
         * 删除轮播图
         */
        @RequiresPermissions("system:picture:remove")
        @Log(title = "轮播图", businessType = BusinessType.DELETE)
        @PostMapping("/remove")
        @ResponseBody
        public AjaxResult remove(String ids) {
            return toAjax(sysMorePictureService.deleteSysMorePictureByIds(ids));
        }


    @RequestMapping("/uploadPicture")
    public String uploadPicture() {
        return prefix + "/more_picture_upload";
    }

    }
